package com.ruix.app.util;

import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapper;
import com.ruix.app.R;
import com.ruix.app.RuiApplication;
import com.ruix.app.widget.GlideCircleTransform;

/**
 * Created by hadexs on 2017/5/12.
 */

public class GlideUitl {


    public static void showImageView(String url,ImageView imgeview,int errorimg) {
        Glide.with(RuiApplication.getAppContext()).load(url)// 加载图片
                .error(errorimg)// 设置错误图片
                .crossFade(200)// 设置淡入淡出效果，默认300ms，可以传参
                .placeholder(errorimg)// 设置占位图
                .diskCacheStrategy(DiskCacheStrategy.ALL)// 缓存修改过的图片
                .into(imgeview);
    }

//.placeholder(me.iwf.photopicker.R.drawable.__picker_ic_photo_black_48dp)
// .error(me.iwf.photopicker.R.drawable.__picker_ic_broken_image_black_48dp)
    public static void showImageView(String url,ImageView draweeView){
        if (TextUtils.isEmpty(url)){
            return;
        }
        Glide.with(RuiApplication.getAppContext()).load(url)
                .thumbnail(0.1f)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.drawable.shape_default_placeholder)
                .error(R.drawable.shape_default_failure)
                .centerCrop()
                .into(draweeView);

    }

    public static void showImageViewNormal(String url,ImageView draweeView){
        if (TextUtils.isEmpty(url)){
            return;
        }
        Glide.with(RuiApplication.getAppContext()).load(url)
                .thumbnail(0.1f)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.drawable.shape_default_placeholder)
                .error(R.drawable.shape_default_failure)
                .into(draweeView);

    }


    public static void showImageViewFitCenter(String url,ImageView draweeView){
        if (TextUtils.isEmpty(url)){
            return;
        }
        Glide.with(RuiApplication.getAppContext()).load(url)
                .thumbnail(0.1f)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.drawable.shape_default_placeholder)
                .error(R.drawable.shape_default_failure)
                .fitCenter()
                .into(draweeView);

    }

    public static void showImageViewCenterCrop(String url,ImageView draweeView){
        if (TextUtils.isEmpty(url)){
            return;
        }
        Glide.with(RuiApplication.getAppContext()).load(url)
                .thumbnail(0.1f)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.drawable.shape_default_placeholder)
                .error(R.drawable.shape_default_failure)
                .centerCrop()
                .into(draweeView);

    }


    public static void showImageViewWithThumb(String url,ImageView draweeView){
        if (TextUtils.isEmpty(url)){
            return;
        }

        Glide.with(RuiApplication.getAppContext()).load(url)
                .thumbnail(0.1f)//color_F9
                .dontAnimate()
                .dontTransform()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.drawable.shape_default_failure)
                .error(R.drawable.shape_default_failure)
                .fitCenter()
                .into(draweeView);

    }

    public static void showImageViewShitWithThumb(String url,ImageView draweeView){
        if (TextUtils.isEmpty(url)){
            return;
        }

        Glide.with(RuiApplication.getAppContext()).load(url)
                .thumbnail(0.1f)//color_F9
                .dontAnimate()
                .dontTransform()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.drawable.shape_default_f9_placeholder)
                .error(R.drawable.shape_default_failure)
                .fitCenter()
                .into(draweeView);

    }

    public static void showImageViewCircle(String url,ImageView draweeView){
        if (TextUtils.isEmpty(url)){
            return;
        }
        Glide.with(RuiApplication.getAppContext()).load(url)
                .thumbnail(0.1f)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.drawable.shape_default_placeholder)
                .error(R.drawable.shape_default_failure)
                .centerCrop()
                .transform(new GlideCircleTransform(RuiApplication.getAppContext()))
                .into(draweeView);

    }


}
